<?php
session_start();
// session variable
$sess_id=$_SESSION['sess_id'];
$sess_user=$_SESSION['sess_user'];
$sess_status=$_SESSION['sess_status'];
if ($sess_id<>session_id() || $sess_user=="" || $sess_status<>"active") {
		$_SESSION['cur_page'] = "index.php";
		header( "Location: login.php");exit();
	}
include('config.inc.php');
include('runid.php');
$appno = $_POST['appno'];
$usrapp = $_POST['userapp'];
$action = $_POST['action'];
$reason = $_POST[reason];
if($action <> ""){
	if($action == 'a'){
		$status = 4;
	}else if($action == 'd'){
		// 6= ไม่อนุมัติ
		$status = 6;
	}
 	$sql = "update approve set app_status=$status,reason='$reason' where approve_no='$appno' and app_user='$usrapp'";
 	$result = mysql_query($sql);
 	@$num = mysql_num_rows($result);
 	$arr = mysql_fetch_array(mysql_query("select fault_no from approve where approve_no='$appno'"));

	if($result){
		$res = mysql_query("update detail set status=$status where no='$arr[fault_no]'");
		if($res){
			echo "<small>".approveMail($appno)."</small>";
			echo "<small>ผลการอนุมัติได้ถูกบันทึกแล้ว</small>";
		}else{
			echo "<small>ไม่สามารถบันทึกผลการอนุมัติได้</small>";
		}
	}else{
		echo "<small>ไม่สามารถบันทึกผลการอนุมัติได้</small>";
	}
}
mysql_close($connect);
?>